package com.five.service.Impl;

import com.five.dao.ClubActivityDao;
import com.five.pojo.ClubActivity;
import com.five.pojo.ClubRegister;
import com.five.pojo.PageBean;
import com.five.service.ClubActivityService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

/**
 * @author lenovo
 */
@Service
public class ClubActivityServiceImpl implements ClubActivityService {
    @Autowired
    ClubActivityDao clubActivityDao;
    //获取所有活动信息
    @Override
    public List<ClubActivity> getAllActivity() {
        List<ClubActivity> list = clubActivityDao.getAllActivity();
        return list;
    }

    //分页查询信息
    @Override
    public PageBean page(Integer page, Integer pageSize , String actName) {
        //1.设置分页参数
        PageHelper.startPage(page , pageSize);
        //2.执行查询
        List<ClubActivity> clubActivityList = clubActivityDao.list2(actName);
        Page<ClubActivity> p = (Page<ClubActivity>) clubActivityList;
        //3.封装PageBean对象
        PageBean pageBean = new PageBean(p.getTotal() , p.getResult());
        return pageBean;
    }

    //报名活动
    @Override
    public void addRegisterInfo(ClubRegister clubRegister) {
        clubActivityDao.addRegisterInfo(clubRegister);
    }
    //根据姓名查是否报名成功
    @Override
    public String findByName(String name){
        String sName = clubActivityDao.findByName(name);
        return sName;
    }

    //管理员：删除活动
    @Override
    public void deleteById(Integer id) {
        clubActivityDao.deleteById(id);
    }

    //团长添加社团活动
    @Override
    public void addActivity(ClubActivity clubActivity) {
        clubActivity.setStatus(0);
        clubActivityDao.addActivity(clubActivity);
    }

    @Override
    public void ModStatus(Integer status, Integer id) {
        clubActivityDao.ModStatus(status , id);
    }

    @Override
    public void ModStatus1(Integer status, Integer id) {
        clubActivityDao.ModStatus1(status , id);
    }

    @Override
    public Integer getClubActivityTotal() {
        Integer total = clubActivityDao.getClubActivityTotal();
        return total;
    }

    //根据社团名称查询
    @Override
    public List<ClubActivity> getByActClub(String actClub) {
        List<ClubActivity> clubActivityList = clubActivityDao.getByActClub(actClub);
        return clubActivityList;
    }

    @Override
    public void updateActivity(ClubActivity clubActivity) {
        clubActivity.setStatus(0);
        clubActivityDao.updateActivity(clubActivity);
    }


}
